﻿<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
	<meta http-equiv="Cache-Control" content="no-siteapp" />
	<link rel="Bookmark" href="/favicon.ico" >
	<link rel="Shortcut Icon" href="/favicon.ico" />
	<!--[if lt IE 9]>
	{js href='/static/admin/lib/html5shiv.js,/static/admin/lib/respond.min.js'}
	<![endif]-->
	{css href='/static/admin/static/h-ui/css/H-ui.min.css,/static/admin/static/h-ui.admin/css/H-ui.admin.css,/static/admin/lib/Hui-iconfont/1.0.8/iconfont.css,/static/admin/static/h-ui.admin/skin/default/skin.css,/static/admin/static/h-ui.admin/css/style.css,/static/admin/static/gloab.css'}
	<!--[if IE 6]>
	{js href='/static/admin/lib/DD_belatedPNG_0.0.8a-min.js'}
	<script>DD_belatedPNG.fix('*');</script>
	<![endif]-->
	<title>权限节点列表</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 管理员管理 <span class="c-gray en">&gt;</span> 权限节点列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<form action="" method="get">
		<div class="text-c">
			新增日期范围：
			<input type="text" onfocus="WdatePicker({ maxDate:'#F{ $dp.$D(\'start_create_at\')||\'%y-%M-%d\' }' })" name="start_create_at" id="start_create_at" class="input-text Wdate" style="width:120px;" value="{$get|get='start_create_at'}" readonly>
			-
			<input type="text" onfocus="WdatePicker({ minDate:'#F{ $dp.$D(\'end_create_at\') }',maxDate:'%y-%M-%d' })" name="end_create_at" id="end_create_at" class="input-text Wdate" style="width:120px;" value="{$get|get='end_create_at'}" readonly>
			<input type="text" class="input-text" style="width:200px" placeholder="输入节点名称" name="name" value="{$get|get='name'}">
			<span class="select-box inline">
				<select name="status" class="select">
					<option value="-1">状态</option>
					{foreach $status as $key => $val}
						<option value="{$key}" {if get($get, 'status') !== NULL && get($get, 'status') == $key}selected{/if}>{$val}</option>
					{/foreach}
				</select>
			</span>
			<span class="select-box inline">
				<select name="category_id" class="select">
					<option value="0">权限分组</option>
					{foreach $category as $key => $_category}
						<option value="{$_category['id']}" {if get($get, 'category_id') == $_category['id']}selected{/if}>{$_category['name']}</option>
					{/foreach}
				</select>
			</span>
			<button type="submit" class="btn btn-success" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜 索</button>
		</div>
	</form>
	<div class="cl pd-5 bg-1 bk-gray mt-20">
		<span class="l">
			{if can('admin/admin/Permission/destory')}
				<a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
			{/if}
			{if can('admin/admin/Permission/create')}
				<a href="javascript:;" onclick="admin_add('添加权限节点','/admin/admin/permission/create','800','500')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加权限节点</a>
			{/if}
			{if can('admin/admin/Permission/auto')}
				<a href="javascript:;" onclick="autoUpdate()" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 自动更新节点</a>
			{/if}
		</span>
		<span class="r">共有数据：<strong>{$count}</strong> 条</span>
	</div>
	<table class="table table-border table-bordered table-bg">
		<thead>
			<tr>
				<th scope="col" colspan="9">权限节点列表</th>
			</tr>
			<tr class="text-c">
				<th width="25"><input type="checkbox" name="" value=""></th>
				<th width="40">ID</th>
				<th width="150">节点名称</th>
				<th width="90">权限分组</th>
				<th width="130">描述</th>
				<th width="130">添加时间</th>
				<th width="100">状态</th>
				<th width="100">操作</th>
			</tr>
		</thead>
		<tbody>
			{volist name='list' id='permission'}
				<tr class="text-c">
					<td><input type="checkbox" value="{$permission.id}" class="id"></td>
					<td>{$permission.id}</td>
					<td>{$permission.name}</td>
					<td>{$permission.categoryname}</td>
					<td>{$permission.description}</td>
					<td>{$permission.create_time|date='Y-m-d H:i:s'}</td>
					<td class="td-status"><span class="label {if $permission.status eq 1}label-success{/if} radius">{$permission.status_text}</span></td>
					<td class="td-manage">
						{if can('admin/admin/Permission/status')}
							<a style="text-decoration:none" {if $permission.status==1}onClick="admin_stop(this,'{$permission.id}')"{else/}onClick="admin_start(this,'{$permission.id}')"{/if} href="javascript:;" title="{$permission.status_text}">
								<i class="Hui-iconfont">{if $permission.status eq 1}&#xe615;{else /}&#xe631;{/if}</i>
							</a>
						{/if}
						{if can('admin/admin/Permission/edit')}
							<a title="编辑" href="javascript:;" onclick="admin_edit('权限节点编辑','/admin/admin/permission/{$permission.id}/edit','{$permission.id}','800','500')" class="ml-5" style="text-decoration:none">
								<i class="Hui-iconfont">&#xe6df;</i>
							</a>
						{/if}
						{if can('admin/admin/Permission/delete')}
							<a title="删除" href="javascript:;" onclick="admin_del(this,'{$permission.id}')" class="ml-5" style="text-decoration:none">
								<i class="Hui-iconfont">&#xe6e2;</i>
							</a>
						{/if}
					</td>
				</tr>
			{/volist}
		</tbody>
	</table>
	{$page|raw}
</div>
{js href="/static/admin/lib/jquery/1.9.1/jquery.min.js,/static/admin/lib/layer/2.4/layer.js,/static/admin/static/h-ui/js/H-ui.min.js,/static/admin/static/h-ui.admin/js/H-ui.admin.js"}
<!--请在下方写此页面业务相关的脚本-->
{js href='/static/admin/lib/My97DatePicker/4.8/WdatePicker.js,/static/admin/lib/datatables/1.10.0/jquery.dataTables.min.js,/static/admin/lib/laypage/1.2/laypage.js'}
<script type="text/javascript">
/*
	参数解释：
	title	标题
	url		请求的url
	id		需要操作的数据id
	w		弹出层宽度（缺省调默认值）
	h		弹出层高度（缺省调默认值）
*/
/*管理员-增加*/
function admin_add(title,url,w,h){
	layer_show(title,url,w,h);
}
/*管理员-删除*/
function admin_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'DELETE',
			url: '/admin/admin/permission/'+id,
			dataType: 'json',
			success: function(data){
				$(obj).parents("tr").remove();
				layer.msg('已删除!',{icon:1,time:1000});
			},
            error:function(XmlHttpRequest, textStatus, errorThrown){
                let errstr = XmlHttpRequest.responseText;
                if ( errstr ) {
                    layer.msg($.parseJSON(errstr).message,{icon:5,time:1000});
                } else {
                    layer.msg('服务错误!',{icon:5,time:1000});
                }
            }
		});		
	});
}
/*管理员-更新节点\分组*/
function autoUpdate(){
    layer.confirm('确认要更新吗？',function(index){
        $.ajax({
            type: 'GET',
            url: '/admin/admin/permission/auto',
            dataType: 'json',
            success: function(data){
                layer.msg('更新成功!',{icon:1,time:1000});
            },
            error:function(XmlHttpRequest, textStatus, errorThrown){
                let errstr = XmlHttpRequest.responseText;
                if ( errstr ) {
                    layer.msg($.parseJSON(errstr).message,{icon:5,time:1000});
                } else {
                    layer.msg('服务错误!',{icon:5,time:1000});
                }
            }
        });
    });
}
/*管理员-编辑*/
function admin_edit(title,url,id,w,h){
	layer_show(title,url,w,h);
}
/*管理员-停用*/
function admin_stop(obj,id){
	layer.confirm('确认要停用吗？',function(index){
		//此处请求后台程序，下方是成功后的前台处理……
		$.ajax({
			url:'/admin/admin/permission/status/'+id,
			method:'get',
			dataType:'json',
			success:function(data){
				$(obj).parents("tr").find(".td-manage").prepend('<a onClick="admin_start(this,\''+id+'\')" href="javascript:;" title="启用" style="text-decoration:none"><i class="Hui-iconfont">&#xe631;</i></a>');
				$(obj).parents("tr").find(".td-status").html('<span class="label label-default radius">禁用</span>');
				$(obj).remove();
				layer.msg('已停用',{icon: 1,time:1000});
			},
            error:function(XmlHttpRequest, textStatus, errorThrown){
                let errstr = XmlHttpRequest.responseText;
                if ( errstr ) {
                    layer.msg($.parseJSON(errstr).message,{icon:5,time:1000});
                } else {
                    layer.msg('服务错误!',{icon:5,time:1000});
                }
            }
		});
		return false;
	});
}

/*管理员-启用*/
function admin_start(obj,id){
	layer.confirm('确认要启用吗？',function(index){
		//此处请求后台程序，下方是成功后的前台处理……
        $.ajax({
            url: '/admin/admin/permission/status/' + id,
            method: 'get',
            dataType: 'json',
            success: function (data) {
                $(obj).parents("tr").find(".td-manage").prepend('<a onClick="admin_stop(this,\''+id+'\')" href="javascript:;" title="停用" style="text-decoration:none"><i class="Hui-iconfont">&#xe615;</i></a>');
                $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">启用</span>');
                $(obj).remove();
                layer.msg('已启用!', {icon: 6,time:1000});
            },
            error:function(XmlHttpRequest, textStatus, errorThrown){
                let errstr = XmlHttpRequest.responseText;
                if ( errstr ) {
                    layer.msg($.parseJSON(errstr).message,{icon:5,time:1000});
                } else {
                    layer.msg('服务错误!',{icon:5,time:1000});
                }
            }
        })
	});
}

/*批量删除*/
function datadel()
{
	layer.confirm('给你个机会考虑清楚',function(index){
		let ids = [];
		$('.id:checked').each(function(){
		    ids.push($(this).val());
		});
		if ( ids.length <= 0 ) {
            layer.msg('请选择行',{icon:5,time:1000});
            return false;
		}
		$.ajax({
			url:'/admin/admin/permission/destory',
			type:'POST',
			data:{ids:ids,_method:"DELETE"},
			dataType:'json',
            success: function (data) {
                $('.id:checked').each(function(){
                    $(this).parents('tr').remove();
                });
                layer.msg('已删除!', {icon: 6,time:1000});
            },
            error:function(XmlHttpRequest, textStatus, errorThrown){
                let errstr = XmlHttpRequest.responseText;
                if ( errstr ) {
                    layer.msg($.parseJSON(errstr).message,{icon:5,time:1000});
                } else {
                    layer.msg('服务错误!',{icon:5,time:1000});
                }
            }
		})
	})
}
</script>
</body>
</html>